<template>
    <div class="brand-records">
        <el-carousel
            ref="brandCarousel"
            indicator-position="none"
            arrow="never"
            height="6rem"
            class="brand-carousel"
            :autoplay="false"
            @change="fnOnIndexChange"
        >
            <el-carousel-item
                v-for="pageIndex in page.total_page"
                :key="pageIndex"
            >
                {{ 'page' + pageIndex }}
                <template v-if="record['page' + pageIndex]">
                    <div
                        class="brand-wrap"
                        :class="{
                            'brand-wrap-hor':
                                record['page' + pageIndex].length == 2
                        }"
                    >
                        <div
                            v-for="(article, aindex) in record[
                                'page' + pageIndex
                            ]"
                            :key="aindex"
                            class="brand-unit"
                        >
                            <div
                                class="cover"
                                :style="{
                                    backgroundImage:
                                        'url(' + article.brand_cover + ')'
                                }"
                            ></div>
                            <div class="type">
                                {{ article.category_title
                                }}{{
                                    article.sub_category_title
                                        ? '/' + article.sub_category_title
                                        : ''
                                }}
                            </div>
                            <div class="title">{{ article.brand_title }}</div>
                            <pre class="content">{{ article.brand_info }}</pre>
                            <div class="author">{{ article.brand_people }}</div>
                            <div class="author2">
                                {{ article.brand_people }}
                            </div>
                        </div>
                        <!-- 站位 -->
                        <div
                            v-if="record['page' + pageIndex].length == 3"
                            class="brand-unit-hide"
                        ></div>
                    </div>
                </template>
                <!-- 加载数据占位 -->
                <template v-else>
                    <div
                        class="brand-wrap"
                        :class="{
                            'brand-wrap-hor':
                                pageIndex == page.total_page &&
                                page.total_count % 4 == 2,
                            'brand-wrap-single':
                                pageIndex == page.total_page &&
                                page.total_count % 4 == 1
                        }"
                    >
                        <div
                            v-for="k in pageIndex == page.total_page
                                ? page.total_count % 4
                                : 4"
                            :key="k"
                            class="brand-unit-seat"
                        >
                            <div class="cover"></div>
                            <div class="type"></div>
                            <div class="title">
                                <div class="title-seat"></div>
                            </div>
                            <div class="content">
                                <div class="content-seat"></div>
                                <div class="content-seat-tail"></div>
                            </div>
                            <div class="author">
                                <div class="author-seat"></div>
                            </div>
                        </div>
                        <!-- 站位 -->
                        <div
                            v-if="
                                pageIndex == page.total_page &&
                                    page.total_count % 4 == 3
                            "
                            class="brand-unit-hide"
                        ></div>
                    </div>
                </template>
            </el-carousel-item>
        </el-carousel>
        <div v-if="page.total_page > 1" class="brand-page-wrap">
            <div
                v-for="i in page.total_page"
                :key="i"
                class="page-wrap"
                :class="{ active: i == page.now_page }"
                @click="getBrandList(i)"
            >
                {{ i }}
            </div>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    data() {
        return {
            record: {},
            page: {
                next_page: 0,
                pre_page: 0,
                now_page: 1,
                total_page: 4,
                page_start: 0,
                page_end: 1,
                total_count: 1,
                page_size: 4
            }
        }
    },
    created() {
        if (!process.server) {
            this.getBrandList(1, true)
        }
    },
    methods: {
        fnChangeIndex(index) {
            // this.functionCurrent = index
            this.$refs.brandCarousel.setActiveItem(index)
        },
        fnOnIndexChange(index) {
            this.currentIndex = index
        },
        getBrandList(page, nochange = false) {
            if (!nochange) {
                this.fnChangeIndex(page - 1)
            }
            this.$post('/Brand/getList', {
                status: -1,
                page_size: 4,
                page_id: page
            }).then((resp) => {
                if (resp.code == 1) {
                    this.record['page' + page] = resp.data.list
                    // this.page.now_page = page
                    this.page = resp.data.page
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.brand-records {
    width: 100%;
    height: 100%;
}
.brand-wrap {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: center;
    flex-wrap: wrap;
    height: 6rem;
    margin-right: -0.24rem;
    margin-bottom: -0.24rem;
}
.brand-wrap-hor {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    height: 6rem;
    padding-bottom: 2.48rem;
    margin-right: -0.24rem;
    margin-bottom: -0.24rem;
}
.brand-wrap-single {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    height: 6rem;
    margin-right: -0.24rem;
    margin-bottom: -0.24rem;
    padding-right: 4.88rem;
    padding-bottom: 2.48rem;
}
.brand-unit-hide {
    width: 4.64rem;
    height: 2.24rem;
    margin-bottom: 0.24rem;
    margin-right: 0.24rem;
    position: relative;
}
.brand-unit {
    width: 4.64rem;
    height: 2.24rem;
    margin-bottom: 0.24rem;
    margin-right: 0.24rem;
    background-color: #fff;
    transition: all linear 0.3s;
    position: relative;
    overflow: hidden;
    &:hover {
        height: 3.22rem;
        .cover {
            top: 0.32rem;
        }
        .type {
            opacity: 0;
        }
        .title {
            top: 0.32rem;
        }
        .content {
            -webkit-line-clamp: 10;
            max-height: 2.38rem;
            top: 0.7rem;
            letter-spacing: 0;
            text-align: justify;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        .author {
            opacity: 0;
            transition: all ease-out 0s;
        }
        .author2 {
            opacity: 1;
            // top: 2.7rem;
        }
    }
}
.brand-unit-seat {
    width: 4.64rem;
    height: 2.24rem;
    margin-bottom: 0.24rem;
    margin-right: 0.24rem;
    background-color: #fff;
    transition: all linear 0.3s;
    position: relative;
    overflow: hidden;
}
.content-seat,
.content-seat-tail {
    width: 2.56rem;
    height: 0.16rem;
    background-color: #f4f4f4;
    margin: 0.04rem 0;
}
.content-seat-tail {
    width: 1.45rem;
}
.title-seat {
    width: 1.3rem;
    height: 24px;
    background-color: #f4f4f4;
    vertical-align: middle;
}
.author-seat {
    width: 1.3rem;
    height: 0.18rem;
    background-color: #f4f4f4;
    vertical-align: middle;
}
.cover {
    width: 1.68rem;
    height: 2.24rem;
    background: #414e62;
    position: absolute;
    left: 0;
    top: 0;
    transition: all linear 0.3s;
    z-index: 1;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}
.type {
    width: 100%;
    height: 0.42rem;
    padding: 0.14rem 0.16rem;
    text-align: right;
    border-bottom: 1px solid #eff3f9;
    transition: all linear 0.3s;
    font-size: 0.14rem;
    font-weight: 400;
    color: rgba(136, 144, 156, 1);
    line-height: 0.14rem;
    z-index: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: all linear 0.3s;
}
.title {
    width: 2.56rem;
    height: 0.24rem;
    font-size: 24px;
    font-weight: 400;
    color: rgba(29, 32, 35, 1);
    line-height: 0.24rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    position: absolute;
    left: 1.78rem;
    top: 0.75rem;
    transition: all linear 0.3s;
}
.content {
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    width: 2.56rem;
    max-height: 0.48rem;
    font-size: 16px;
    font-weight: 400;
    color: rgba(136, 144, 156, 1);
    line-height: 0.24rem;
    position: absolute;
    left: 1.78rem;
    top: 1.13rem;
    transition: all linear 0.3s;
}
.author {
    width: 2.5rem;
    height: 0.18rem;
    font-size: 18px;
    font-weight: 500;
    color: rgba(29, 32, 35, 1);
    line-height: 0.18rem;
    position: absolute;
    top: 1.75rem;
    left: 1.78rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: all ease-out 0.3s;
    transition-delay: 0.3s;
}
.author2 {
    width: 1.48rem;
    height: 0.18rem;
    font-size: 18px;
    font-weight: 500;
    color: rgba(29, 32, 35, 1);
    line-height: 0.18rem;
    text-align: center;
    position: absolute;
    left: 0.1rem;
    top: 2.7rem;
    opacity: 0;
    transition: all linear 0.3s;
}
.brand-page-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.page-wrap {
    width: 0.24rem;
    height: 0.24rem;
    background: rgba(251, 251, 251, 0.1);
    border-radius: 0.18rem;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
    line-height: 0.24rem;
    text-align: center;
    margin: 0 4px;
    cursor: pointer;
    &.active {
        background: rgba(32, 160, 255, 1);
    }
    &:hover {
        background: rgba(32, 160, 255, 1);
        .brand-page-wrap {
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
}
.brand-carousel {
    width: 100%;
}
</style>
